<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>非受控组件</title>
  </head>
  <body>
    <div id="test"></div>
    <!-- 引入react核心库  优先 -->
    <script type="text/javascript" src="../js/react.development.js"></script>
    <!-- 引入react-dom用于支持react操作DOM，依赖react核心库 -->
    <script
      type="text/javascript"
      src="../js/react-dom.development.js"
    ></script>
    <!-- 引入babel，用于将jsx转换为js -->
    <script type="text/javascript" src="../js//babel.min.js"></script>
    <script type="text/babel">
      // 1.非受控组件：现用现取！！！！！！
      class Demo extends React.Component {
        login = (event) => {
          event.preventDefault();
          const { nameValue, passwordValue } = this;
          console.log("登录了", nameValue.value, passwordValue.value);
          console.log("event对象", event);
        };

        render() {
          return (
            <form action="" onSubmit={this.login}>
              用户名：
              <input
                type="text"
                ref={(c) => {
                  this.nameValue = c;
                }}
                name="username"
              />
              密码：
              <input
                type="password"
                ref={(c) => {
                  this.passwordValue = c;
                }}
                name="password"
              />
              <button type="submit">登录</button>
            </form>
          );
        }
      }
      ReactDOM.render(<Demo />, document.getElementById("test"));
    </script>
  </body>
</html>
